import string
import random
import time
# 自定义激活表列表
passwd_list= ['Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M',
                'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m',
                 0,1,2,3,4,5,6,7,8,9]
# list转换为string不能包含数字，如果包含需要进行如下转换，把数字转换为字符串
str1 = "".join('%s' %id for id in passwd_list)

# 随机生产激活码函数
def key_code(num):
    with open("激活码.txt", "w+") as f2:
        f2.read()
    for num in range(0, input1):
        str2 = "".join((random.sample(str1, 32)))
        time.sleep(0.5)
        print(f'第{num + 1}个激活码是：{str2}')
        with open("激活码.txt", 'a+') as fp:
            fp.write(str2 + '\n')
    print("激活码生产完毕！")

# 主程序
print(f'{"激活码程序":#^50}')
while True:
 input1 = int(input(f'请输入你需要的激活码个数：'))
 if input1 == 0:
    print("输入有误，重新输入！")
 else:
     key_code(input1)
     break
with open("激活码.txt", 'r+') as f:
    print(f.read())
